/******************************************************************************
** @file	test_cm_dblitemanager.cpp
** @author  Nestor Felipe
**
** @date	Sep 01, 2010
**
** @desc	This testSuite tests the creating of database and tables.
*			
******************************************************************************/

//#include <stdio.h>
#include "unit--/unit--.h"
#include "cm_dblitemanager.h"
#include "adcm_computer.h"

using namespace unit_minus;

testSuite(CacheManager);

testCase(createDatabaseTest, CacheManager)
{
    CM_DBLiteManager manager ;
	int res = manager.initialize();
	assertTrue(res == 1);
}	

testCase(retrieveComputersTest, CacheManager)
{
   	CM_DBLiteManager mng ;

	mng.initialize();
	const wstring myDomain = L"my fully Qualified";

	ADCM_Domain domain(wstring(L"my own domain"), wstring(myDomain));
	int resp = mng.saveDomain(domain);
	assertTrue(resp == 1);

	ADCM_Computer first_compu(wstring(L"cn first machine xp"), wstring(L"this not is a powerfull linux"));
	ADCM_Computer second_compu(wstring(L"cn second machine vista"), wstring(L"this not is a powerfull slackware"));
	ADCM_Computer third_compu(wstring(L"cn third machine windows 7"), wstring(L"another f*** operating system"));

	resp = mng.saveComputer(domain.getDomainID(), first_compu);
	assertTrue(resp == 1);

	resp = mng.saveComputer(domain.getDomainID(), second_compu);
	assertTrue(resp == 1);

	resp = mng.saveComputer(domain.getDomainID(), third_compu);
	assertTrue(resp == 1);

	vector<ADCM_Computer> computers;
	resp = mng.getComputers(wstring(myDomain), computers);

	assertTrue(resp == 1);

	resp = mng.saveComputer(domain.getDomainID(), second_compu);

	//this computer must be exist
	assertTrue(resp == 0);
}


testCase(insertComputerTest, CacheManager)
{
    cout << "----- Start insertComputersTest -----" << endl;
    CM_DBLiteManager manager ;
	manager.initialize();

	ADCM_Domain domain(wstring(L"my domain"), wstring(L"fullQualified"));
	int res = manager.saveDomain(domain);
    assertTrue(domain.getDomainID() > 0);
    assertTrue(res == 1);

	ADCM_Computer first_compu(wstring(L"cn first machine"), wstring(L"not is a powerfull linux"));
	res = manager.saveComputer(domain.getDomainID(), first_compu);
    assertTrue(first_compu.getIdComputer() > 0);
    assertTrue(res == 1);
	cout << "------- End insertComputersTest ------" << endl;
}

